package Servlet.Edit;


import Server.Add.novelServer;
import Server.List.novelListServer;
import bean.userBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/novelEdit")
public class novelEdit extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");		
		//java.io.PrintWriter out = response.getWriter();
		String msg = "";	
		String url = "novelEdit.jsp";
		
		try {
			HttpSession session = request.getSession();
			userBean user= (userBean) session.getAttribute("user");
			if (user == null || !user.getUserType().equals("admin")) {							//如果登录已失效，或权限不足
				msg = "图片没有更新。您的登录已失效。";
				msg += "（<a href='login.jsp' target='_top'>用户登录</a>）</p>";	//前往最外层的框架集，即整个浏览器窗口
				return;
			}
			
			novelListServer server = new novelListServer(request,response);
			server.selectById(request);
			

		} catch (Exception e) {
			msg += "系统发生错误。";	
			e.printStackTrace();
		} finally {
			if (request.getAttribute("msg") != null) {
				msg += request.getAttribute("msg").toString();
			}
			request.setAttribute("msg", msg);
			
			request.getRequestDispatcher(url).forward(request, response);
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
